#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<cstdlib>//rand()
#define rep(i,a,b) for(register int i = (a);i <= (b);++i)
#define per(i,a,b) for(register int i = (a);i >= (b);--i)
typedef long long ll;
typedef unsigned long long ull;
using std::string;using std::cin;using std::cout;
using std::set;
set<int> st[5050];
int n,m,u,v,U[5010],V[5010],aans[10010][3],ans[10010],enter,cnt,FFF,Ans;
bool flag[5010],fflag,mark[5010][5010];

inline bool cmp(int x,int y){return x < y;}

inline void dfs1(int now){
    if(cnt == n) return;
    for(set<int>::iterator it = st[now].begin();it != st[now].end();++it){
        if(!flag[*it]) {
            flag[*it] = true , ans[++cnt] = *it;
            dfs1(*it);
        }
    }
    return;
}

inline void solve1(){
    rep(i,1,m){
        cin >> u >> v;
        st[u].insert(v) , st[v].insert(u);
    }
    flag[1] = true , ans[++cnt] = 1;
    dfs1(1);
    rep(i,1,cnt) cout << ans[i] << " "; 
    return;
}

inline void dfs2(int now){
    if(cnt == n) return;
    for(set<int>::iterator it = st[now].begin();it != st[now].end();++it){
        if(u == now && v == *it) continue;
        if(v == now && u == *it) continue;
        if(!flag[*it]) {
            flag[*it] = true , aans[++cnt][2] = *it;
            dfs2(*it);
        }
    }
    return;
}

inline bool have_c(){
    if(mark[u][v] || mark[v][u]) return true;
    return false;
}

inline void dfs_fc(int now,int fa){
    // cout << now << " " << flag[now] << "\n";
    if(flag[now] && now != 1){
        enter = now;
        mark[now][fa] = mark[fa][now] = true;
        FFF = 1;
        return;
    } else flag[now] = true;
    for(set<int>::iterator it = st[now].begin();it != st[now].end();++it){
        if(*it != fa){
            dfs_fc(*it,now);
            if(FFF == 1 && now != enter) mark[now][fa] = mark[fa][now] = true;
            if(FFF != 0 && now == enter){
                FFF = -1;return;
            } else if(FFF != 0 && now != enter) return;
        }
    }
}

inline void find_c(){
    memset(flag,false,sizeof(flag));
    flag[1] = true;
    dfs_fc(1,0);
    memset(flag,false,sizeof(flag));
}

inline void solve2(){
    Ans = 2e9+9;

    rep(i,1,m){
        cin >> U[i] >> V[i];
        st[U[i]].insert(V[i]) , st[V[i]].insert(U[i]);
    }
    find_c();
    rep(i,1,m){
        u = U[i] , v = V[i];
        // cout << i << " " << have_c() << "\n";
        if( !have_c() ) continue;
        rep(j,1,n) aans[j][2] = 0;
        memset(flag,false,sizeof(flag));
        cnt = 0;
        flag[1] = true , aans[++cnt][2] = 1;
        dfs2(1);
        if(aans[1][1] == 0){
            rep(i,1,n) aans[i][1] = aans[i][2];
        } else {
            int p = 1;
            while(p <= n && aans[p][1] == aans[p][2]) ++p;
            if(aans[p][1] < aans[p][2]) continue;
            else for(;p <= n;++p) aans[p][1] = aans[p][2]; 
        }
    }
    rep(i,1,n) cout << aans[i][1] << " ";
    cout << "\n";
}

int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("in.in", "r", stdin);
    cin >> n >> m;
    if(n == m) solve2();
    else solve1();
    return 0;
}